﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Marbles.Core.Web.Syndication;
using Marbles.Core.Web.Syndication.RSS;
using Marbles.Core.Web.Syndication.Atom;

namespace Marbles.CMS.ContentTypes.Blog
{
    public class BlogEntry
    {
        public string Author { get { return this._Author; } set { this._Author = value; } }
        public int Index { get { return this._Index; } set { this._Index = value; } }
        public string Description { get { return this._Description; } set { this._Description = value; } }
        public Uri Link { get { return this._Link; } set { this._Link = value; } }
        public string Title { get { return this._Title; } set { this._Title = value; } }
        public Guid Guid { get { return this._Ident; } set { this._Ident = value; } }
        public DateTime PublishDate { get { return this._PubDate; } set { this._PubDate = value; } }

        private string _Author = string.Empty;
        private int _Index = int.MinValue;
        private string _Title = string.Empty;
        private string _Description = string.Empty;
        private Uri _Link = null;
        private Guid _Ident = Guid.Empty;
        private DateTime _PubDate = DateTime.MinValue;

        public RSSItem ToRSS()
        {
            RSSItem newitem = new RSSItem();
            newitem.Description = Description;
            newitem.Title = Title;
            newitem.PublishDate = PublishDate;
            newitem.Guid = Guid;
            newitem.Link = Link;
            return newitem;
        }

        public AtomItem ToAtom()
        {
            AtomItem newitem = new AtomItem();
            newitem.Content = Description;
            newitem.Description = Description;
            newitem.Title = Title;
            newitem.PublishDate = PublishDate;
            newitem.ID = Guid.ToString();
            newitem.Link = Link;
            if (this.Author != string.Empty) { newitem.Author.Add(new AtomAuthor(this.Author, string.Empty, null)); }
            return newitem;
        }

    }
}
